using System;

public class WeaverAssemblyPathFinder : MarshalByRefObject
{
    public AddinFilesEnumerator AddinFilesEnumerator;
    public WeaverProjectFileFinder WeaverProjectFileFinder;
    public bool WeaverProjectUsed;

    public string FindAssemblyPath(string weaverName)
    {
        var weaverProjectContains = WeaverProjectContainsType(weaverName);
        if (weaverProjectContains)
        {
            return WeaverProjectFileFinder.WeaverAssemblyPath;
        }
        var assemblyPath = AddinFilesEnumerator.FindAddinAssembly(weaverName + ".Fody");
        if (assemblyPath != null)
        {
            var check = ContainsTypeChecker.Check(assemblyPath, "ModuleWeaver");
            if (check)
            {
                return assemblyPath;
            }
        }
        return null;
    }

    public bool WeaverProjectContainsType(string weaverName)
    {
        if (WeaverProjectFileFinder.Found)
        {
            var check = ContainsTypeChecker.Check(WeaverProjectFileFinder.WeaverAssemblyPath, weaverName);
            if (check)
            {
                WeaverProjectUsed = true;
                return true;
            }
        }
        return false;
    }
}